package ControllerLayer;
import ModelLayer.*;




import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.util.Date;

/**
 * The test class testRentalCtr.
 *
 * @author  (your name)
 * @version (a version number or a date)
 */
public class testRentalCtr
{
    private ControllerLayer.RentalCtr rentalC1;
    private AddressCtr addressC1;
    private ToolCtr toolC1;
    private Date b;
    private Date a;
    private Date c;
    private Date d;
    private Date e;
    /**
     * Default constructor for test class testRentalCtr
     */
    public testRentalCtr()
    {
      rentalC1 = rentalC1.getInstance(); 
      addressC1 = AddressCtr.getInstance();
      toolC1 = ToolCtr.getInstance();
    }

    /**
     * Sets up the test fixture.
     *
     * Called before every test case method.
     */
    @Before
    public void setUp()
    {
        addressC1.createCustomer("Anders", "Karljohanvej 7", "89874521", "larskarlson@gmail.com", 100.0, 20.0);
        addressC1.createEmployee("Lars", "Sønderholmsvej 8",  "30285018", "andersh@gmail.com","abc123");
        addressC1.createEmployee("Flemming", "Sønderholmvej 18", "93456643", "flemminga@gmail.com", "602090");
        addressC1.createCustomer("Jakob", "Albertvej 8", "28309012", "jakoba@gmail.com", 100.0, 10.0);
        
        addressC1.deletePerson(3);
        addressC1.deletePerson(4);
        
        toolC1.createToolDescription("svensknøjle", 50.0);
        toolC1.createToolDescription("gravmaskine", 1000.0);
        toolC1.createTool(1,1220);
        
        a = new Date(107, 7, 19);
        b = new Date(107, 7, 20);
     
        c = new Date(112, 11, 15);
        d = new Date(111, 7, 10);
        e = new Date(112, 11, 16);
        
      
       
      
    }

    /**
     * Tears down the test fixture.
     *
     * Called after every test case method.
     */
    @After
    public void tearDown()
    {
    }

    //This test is testing 3a from fully dressed description of tool reservation - alternative flow.
    @Test
    public void testGetCustomer()
    {
       assertEquals("Anders", addressC1.getPerson(1).getName()); 
    }
    
    //This test is testing 3a from fully dressed description of tool reservation - alternative flow.
    @Test
    public void testGetEmployee()
    {
       assertEquals("Lars", addressC1.getPerson(2).getName()); 
    }
    
    //This test is testing 3a from fully dressed description of tool reservation - alternative flow.
    @Test
    public void testGetPersonWhoDontExist()
    {
       assertNull(addressC1.getPerson(4)); 
    }
    
    //This test is testing 8a from fully dressed description of tool reservation - alternative flow.
    @Test
    public void testCreateRentalWithOldDates()
    {
       rentalC1.createRental((Customer) rentalC1.getPerson(1),(Employee) rentalC1.getPerson(2), rentalC1.getToolDescription(1), a, b, a, 1);
    }
    
    //This test is testing 10a from fully dressed description of tool reservation - alternative flow.
    @Test
    public void testCreateRentalWithOlderBeginDate()
    {
       rentalC1.createRental((Customer) rentalC1.getPerson(1),(Employee) rentalC1.getPerson(2), rentalC1.getToolDescription(1), c, d, c, 1);
    }
    
    //This test is testing 11 from fully dressed description of tool reservation - basic flow.
    @Test
    public void testCreateRental()
    {
       rentalC1.createRental((Customer) rentalC1.getPerson(1),(Employee) rentalC1.getPerson(2), rentalC1.getToolDescription(1), e, c, e, 1);
    }
    
    //This test is testing 11a from fully dressed description of tool reservation - alternative flow.
    @Test
    public void testCreateRentalOnReservedTool()
    {
        rentalC1.createRental((Customer) rentalC1.getPerson(1),(Employee) rentalC1.getPerson(2), rentalC1.getToolDescription(1), e, c, e, 1);
        rentalC1.createRental((Customer) rentalC1.getPerson(1),(Employee) rentalC1.getPerson(2), rentalC1.getToolDescription(1), e, c, e, 1);
    }
    
}

